<?php

namespace app\admin\controller;

use app\admin\model\LevelModel;
use think\Db;
 
class Level extends Base
{

    /**
     * [index 轮播列表]
     * @return [type] [description]
     * @author felix
     */
    public function index(){

        $key = input('key');
        $map = [];
        //$map['is_show'] = 1;
        if($key&&$key!==""){
            $map['name'] = ['like',"%" . $key . "%"];
        }
        $Nowpage = input('get.page') ? input('get.page'):1;
        $limits = config('list_rows');// 获取总条数
        $count = Db::name('level')->where($map)->count();//计算总页面
        $allpage = intval(ceil($count / $limits));
        $data = new LevelModel();
        $lists = $data->getDataByWhere($map, $Nowpage, $limits);
        $this->assign('Nowpage', $Nowpage); //当前页
        $this->assign('allpage', $allpage); //总页数
        $this->assign('val', $key);
        if(input('get.page'))
        {
            return json($lists);
        }
        return $this->fetch();
    }




    /**
     * @return [type] [description]
     * @author felix
     */
    public function levelAdd()
    {
        if(request()->isAjax()){

            $param = input('post.');
            //dump($param);die;
            $data = new LevelModel();
            $flag = $data->insertData($param);
            return json(['code' => $flag['code'], 'data' => $flag['data'], 'msg' => $flag['msg']]);
        }
        return $this->fetch();
    }


    /**
     * @return [type] [description]
     * @author felix
     */
    public function levelEdit()
    {
        $data = new LevelModel();
        if(request()->isAjax()){

            $param = input('post.');
            $flag = $data->updateData($param);
            return json(['code' => $flag['code'], 'data' => $flag['data'], 'msg' => $flag['msg']]);
        }

        $id = input('param.id');
        $this->assign('level',$data->getOneData($id));
        return $this->fetch();
    }


    /**
     * @return [type] [description]
     * @author felix
     */
    public function levelDel()
    {
        $id = input('param.id');
        $data = new LevelModel();
        $flag = $data->delData($id);
        return json(['code' => $flag['code'], 'data' => $flag['data'], 'msg' => $flag['msg']]);
    }



    /**
     * @return [type] [description]
     * @author felix
     */
    /*public function banner_state()
    {
        $id = input('param.id');
        $status = Db::name('banner')->where('id',$id)->value('is_show');//判断当前状态情况
        if($status==1)
        {
            $flag = Db::name('banner')->where('id',$id)->setField(['is_show'=>-1]);
            return json(['code' => 1, 'data' => $flag['data'], 'msg' => '已隐藏']);
        }
        else
        {
            $flag = Db::name('banner')->where('id',$id)->setField(['is_show'=>1]);
            return json(['code' => 0, 'data' => $flag['data'], 'msg' => '已显示']);
        }

    }*/


}